package tests;

import gameComponents.Player;
import gamePieces.Rook;

import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author Selman Selman
 *
 */
public class RookTest extends TestCase {

	Player p = new Player(1);
	Rook r = new Rook(0,0,p);
	/**
	 * @param name
	 */
	public RookTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link Rook#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if rook moves vertically
		assertTrue(r.checkIfLegal(0,5));
		//check if rook moves horizontally
		assertTrue(r.checkIfLegal(2,0));
		//check if rook wont move diagonally
		assertFalse(r.checkIfLegal(1,1));
	}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since rook is created initially at (0,0)
		//getX() should return 0
		assertEquals(r.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since rook is created initially at (0,0)
		//getY() should return 0
		assertEquals(r.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		r.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(r.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(r.getOwnership(),p);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		r.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(r.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		r.possibleMoves();
		ArrayList<Point> p = r.getMoves();
		for(int i = 1; i<8; i++){ //makes sure vertical moves are included in array
			assertTrue(p.contains(new Point(0,i)));
		}
		for(int i = 1; i<8; i++){ //makes sure horizontal moves are included in array
			assertTrue(p.contains(new Point(i,0)));
		}
	}

	/**
	 * Test method for {@link Piece#move(int, int)}.
	 * @author Selman Selman
	 */
	public final void testMove() {
		//checks if rook will move forward 
		r.move(0,2);
		assertEquals(r.getX(),0);
		assertEquals(r.getY(), 2);
		
		//new x and y coordinates are 0 and 2 respectively 
		//check if queen will move horizantally
		r.move(3,2); // knight should not move
		assertEquals(r.getX(),3);
		assertEquals(r.getY(),2);
		
		//checks if rook will not move  diagonally
		r.move(4,3);
		assertEquals(r.getX(),3);
		assertEquals(r.getY(),2);
		//move queen out of boundaries
		r.move(9,9); //queen should not move
		assertEquals(r.getX(),3);
		assertEquals(r.getY(),2);
	}

}
